<!-- 
 * 查看消息
 * @author: 
 * @since: 2022-05-24
 * look.vue
-->
<template>
  <div class="look-info-container detailsPageBox p20">
    <div class="detailsMain">
      <div class="pushNum">
        <div class="totalNum common">
          <div class="left">
            <div class="num">{{ state.pushNum.total }}</div>
            <div class="word">
              <svg-icon name="zongrenshu" color="#00A2FF" size="20px"></svg-icon>
              <span class="tip">推送总人数</span>
            </div>
          </div>
          <div class="right" @click="look(1)">
            <div class="look">查看</div>
          </div>
        </div>
        <div class="alreadyNum common">
          <div class="left">
            <div class="num">{{ state.pushNum.readTotal }}</div>
            <div class="word">
              <svg-icon name="yidu" color="#25D390" size="20px"></svg-icon>
              <span class="tip">已读人数</span>
            </div>
          </div>
          <div class="right" @click="look(2)">
            <div class="look">查看</div>
          </div>
        </div>
        <div class="unreadNum common">
          <div class="left">
            <div class="num">{{ state.pushNum.notReadTotal }}</div>
            <div class="word">
              <svg-icon name="weidudianjihou" color="#F74B33" size="20px"></svg-icon>
              <span class="tip">未读人数</span>
            </div>
          </div>
          <div class="right" @click="look(3)">
            <div class="look">查看</div>
          </div>
        </div>
      </div>
      <div class="pushDetails">
        <div class="common">
          <span class="key">消息标题：</span>
          <span class="value">{{ state.infoItem.customMessageTitle }}</span>
        </div>
        <div class="common">
          <span class="key">消息内容：</span>
          <span class="value">{{ state.infoItem.customMessageContent }}</span>
        </div>
        <div class="common">
          <span class="key">推送群体：</span>
          <span class="value">{{ state.infoItem.customMessagePushRoleName }}</span>
        </div>
        <div class="common">
          <span class="key">推送方式：</span>
          <span class="value">{{ state.infoItem.customMessagePushType }}</span>
        </div>
      </div>
    </div>
    <el-dialog v-model="isShowDialog" :title="state.dialogTitle">
      <div class="export">
        <svg-icon name="daochu1" size="16px" color="#00A2FF"></svg-icon>
        <span class="word">导出列表</span>
      </div>
      <div class="search">
        <el-form :inline="true" :model="state.formModel" class="demo-form-inline">
          <el-form-item label="用户名：">
            <el-input v-model="state.formModel.userName" placeholder="请输入用户名" clearable @change="search" />
          </el-form-item>
        </el-form>
      </div>
      <div class="table">
        <TableCom :tableHeader="state.tableHeader" :tableData="state.tableData" :pagination="state.pagination" :loading="loading" :isShowTableBtn="false" @getCurrentChange="getCurrentChange" @getSizeChange="getSizeChange" :isShowGrooveHandleCol="false" :isShowLogicHandleCol="false" :isShowCheckbox="false" class="tableCom"></TableCom>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, ref, reactive } from 'vue';
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { sessionstorage } from '@/utils/storage.js'
import { customInfoDetailsApi, customInfoReadDetailApi } from '@/api/interface/info.js'

const store = useStore();
const router = useRouter();


const state = reactive({
  infoItem: {},//每条消息数据
  dialogTitle: '',//弹窗标题
  formModel: {//弹窗参数
    userName: '',//用户名字
    readStatus: '',//阅读状态
  },
  tableData: [
  ],
  tableHeader: [
    {
      label: '姓名',
      prop: "receiveUserId",
    },
  ],
  pagination: {//分页
    currentPage: 1,
    size: 10,
    total: 0,
  },
  pushNum: {},//推送数据


})

const isShowDialog = ref(false)
const loading = ref(false)

onMounted(() => {
  const level = router.currentRoute.value.meta.level
  store.dispatch('setting/setRouterCut', level);
  state.infoItem = sessionstorage.get('infoItem')
  customInfoDetails()
})

onUnmounted(() => {
  store.dispatch('setting/setRouterCut', 2);
})

//获取自定义消息详情消息
const customInfoDetails = () => {
  const params = {
    id: state.infoItem.id
  }
  customInfoDetailsApi(params).then(res => {
    const { data, status } = res
    if (status === 200) {
      state.pushNum = data
    }

  })
}

//获取自定义消息阅读明细
const customInfoReadDetail = () => {
  const params = {
    ipi: state.pagination.currentPage,
    ips: state.pagination.size,
    userName: state.formModel.userName,
    readStatus: state.formModel.readStatus
  }
  customInfoReadDetailApi(params).then(res => {
    const { data, status } = res
    if (status === 200) {
      state.tableData = data.result
      state.pagination.currentPage = data.pageNum
      state.pagination.size = data.pageSize
      state.pagination.total = data.total
    }
  })

}

const look = (type) => {//1.推送总人数 2.已读人数 3.未读人数
  console.log('look');
  isShowDialog.value = true
  switch (type) {
    case 1:
      state.dialogTitle = "推送总人数列表"
      state.formModel.readStatus = ''
      customInfoReadDetail()
      state.tableHeader.splice(1, 1)
      break;
    case 2:
      state.dialogTitle = "已读人数"
      state.formModel.readStatus = true
      customInfoReadDetail()
      if (state.tableHeader.length === 1) {
        const list = {
          label: '已读时间',
          prop: "readDate",
        }
        state.tableHeader.push(list)
      }
      break;
    case 3:
      state.dialogTitle = "未读人数"
      state.formModel.readStatus = false
      customInfoReadDetail()
      state.tableHeader.splice(1, 1)
      break;

  }
}

const search = () => {
  customInfoReadDetail()

}

//点击当前页
const getCurrentChange = (val) => {
  state.pagination.currentPage = val;
  customInfoReadDetail()
}

//点击条数
const getSizeChange = (val) => {
  state.pagination.size = val;
  customInfoReadDetail()
}

</script>

<style lang="scss" scoped>
.look-info-container {
  .pushNum {
    display: flex;
    .common {
      width: 320px;
      height: 100px;
      border: 1px solid #e3e3e3;
      border-radius: 8px;
      display: flex;
      margin-right: 60px;
      .left {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .num {
          font-weight: bold;
          font-size: 24px;
          color: #333333;
        }
        .word {
          display: flex;
          align-items: center;
          margin-top: 18px;
          .tip {
            color: #666666;
            font-size: 18px;
            margin-left: 10px;
          }
        }
      }
      .right {
        width: 100px;
        height: auto;
        color: #00a2ff;
        font-size: 18px;
        cursor: pointer;
        text-align: center;
        padding: 20px 0;
        box-sizing: border-box;
        .look {
          width: 100%;
          border-left: 1px solid #e3e3e3;
          height: 60px;
          line-height: 60px;
        }
      }
    }
  }
  .pushDetails {
    font-size: 16px;
    color: #333333;
    margin-top: 40px;
    .common {
      margin-top: 30px;
      .key {
        font-weight: bold;
      }
    }
  }
  .el-dialog__body {
    .export {
      width: 100%;
      display: flex;
      justify-content: flex-end;
      cursor: pointer;
      .word {
        font-weight: bold;
        color: #00a2ff;
        font-size: 16px;
      }
    }
  }
  :deep(.el-form-item__label) {
    line-height: 40px !important;
  }
  :deep(.el-form-item__content) {
    width: 200px !important;

    .el-input__inner {
      height: 40px;
      line-height: 40px;
    }
  }
  .tableCom {
    padding: 0;
  }
}
</style>
